﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Xml;
//using ServiceOne;
//using Neuron.Samples.Headers;
using System.Xml.Linq;
using System.Net;
using Neuron.Esb;
using PassportsModel;
using System.IO;
using Shared.Utilities;


namespace NeuronESBAccess
{
    public static class NeuronClient
    {
//        const string _msg = @"<PurchaseRequest>
//                                <Products>
//                                    <Product name='BigBox' quanity='10' location='Denver'></Product>
//                                </Products>
//                            </PurchaseRequest>";

        /// <summary>
        /// In this example, we're dynamically looking up the Neuron hosted client service information By using the 
        /// name of the Neuron Client Connector.  This uses the Client<T> interface from Neuron.
        /// Then we send the message under the covers using WCF, and we use the
        /// In_Router_Code or In_Router_Rules Neuron pipeline to route to endpoint.
        /// Using Client<T> interface the user making the call doesn't have to know WCF symantics
        /// </summary>
        public static Message ClientTSendRequestByServiceName(PassportRequest passportRequest)
        {
            XmlReader xmlReader = null;
            Message reqMsg = null;
            Message replyMsg = null;
            //string action = "V2";
            string action = null;

            using (Client<IRequestChannel> client = new Client<IRequestChannel>("ClientNewPassportApplicationRequest"))
            {
                using (xmlReader = Serialization.CreateMessage(passportRequest))
                {
                    using (reqMsg = Message.CreateMessage(MessageVersion.Default, action, xmlReader))
                    {
                        replyMsg = client.Proxy.Request(reqMsg);
                        //Console.WriteLine(client.Proxy.Request(reqMsg).ToString());
                        reqMsg.Close();
                    }
                    xmlReader.Close();
                }
            }
            return (replyMsg);
        }
       
        
    }
}
